package ArrayAndString;

public class DoublePointer_1 {

    public static void main(String[] args) {
        String s = "我是猪";
        String s1 = reversStr(s);
        System.out.println(s1);

    }

    public static String reversStr(String str) {
        int i = 0;
        int j = str.length() - 1;

        char[] chars = str.toCharArray();
        while (i < j) {
            char temp = chars[i];
            chars[i] = chars[j];
            chars[j] = temp;
            i++;
            j--;
        }
        return new String(chars);
    }

    public void reverseString(char[] s) {
        int i = 0;
        int j = s.length - 1;
        while (i < j) {
            char temp = s[i];
            s[i] = s[j];
            s[j] = temp;
            i++;
            j--;
        }
    }
}
